package com.tianzeculture.stagebao.activity.home.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;

import java.util.List;

/**
 * Created by Administrator on 2018/6/5 0005.
 */

public class CharacteristicAdapter extends RecyclerView.Adapter<CharacteristicAdapter.RecyclerViewHolder> {
    Context context;
    List<String> strings;

    public CharacteristicAdapter(Context context, List<String> strings) {
        this.context = context;
        this.strings = strings;
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_characteristic, parent, false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }


    class RecyclerViewHolder extends RecyclerView.ViewHolder {
        TextView tvCharacteristic;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
            tvCharacteristic = itemView.findViewById(R.id.tvCharacteristic);
        }

        public void setData(int position) {
            tvCharacteristic.setText(strings.get(position));
            if (position % 4 == 0)
                tvCharacteristic.setBackgroundResource(R.drawable.bg_lightpink_round);
            else if (position % 4 == 1)
                tvCharacteristic.setBackgroundResource(R.drawable.bg_lightpurple_round);
            else if (position % 4 == 2)
                tvCharacteristic.setBackgroundResource(R.drawable.bg_lightorange_round);
            else if (position % 4 == 3)
                tvCharacteristic.setBackgroundResource(R.drawable.bg_lightgreen_round);
        }
    }
}
